# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=verilator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.202
pkgrel=1
pkgdesc="The fastest free Verilog HDL simulator (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.veripool.org/projects/verilator/wiki/Intro"
license=("LGPL")
groups=("${MINGW_PACKAGE_PREFIX}-eda")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "flex")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")

source=("${_realname}::https://codeload.github.com/${_realname}/${_realname}/tar.gz/v${pkgver}")
sha256sums=('a60c02f299ddb5bb8e963dc7d81983c55c293d97718685c1cd4b66638a33d98e')

prepare() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  sh autoconf
}

build() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  cp /usr/include/FlexLexer.h src/

  export MSYS2_ARG_CONV_EXCL="-DDEFENV"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
